/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treccontextsug;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author manzato
 */
public class SuggestionsOutput {

    private String filename;
    private String runId;
    private BufferedWriter out;
    private final String groupId = "ICMC_USP";

    public SuggestionsOutput(String filename, String runId) {
        this.filename = filename;
        this.runId = runId;
        try {
            out = new BufferedWriter(new FileWriter(filename));
            out.write("groupid,runid,profile,context,rank,title,description,url,docId");
            out.newLine();
        } catch (IOException ex) {
            Logger.getLogger(SuggestionsOutput.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void addSuggestion(String profileId, String contextId, int rank, String title, String description, String url) {
        try {
            out.write(groupId + "," + runId + "," + profileId + "," + contextId + "," + rank + ",\"" + title + "\",\"" + description + "\",\"" + url + "\",");
            out.newLine();
        } catch (IOException ex) {
            Logger.getLogger(SuggestionsOutput.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public void closeFile() {
        try {
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(SuggestionsOutput.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
